﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.Common;
using System.IO;
using BOHVote.BLL;

namespace BOH.AccreditationSystem
{
    public partial class PPTFileUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ApplyID"] != null)
                {
                    LoadApplyInfo(Request.QueryString["ApplyID"].ToString());
                }
            }
        }

        private void LoadApplyInfo(string ApplyID)
        {
            DataSet dst = ApplyClass.getApplyByID(ApplyID);
            if (dst != null&&dst.Tables[0].Rows.Count>0)
            {
                labApplyName.Text = dst.Tables[0].Rows[0]["Apply_Name"].ToString();
                labIDCard.Text = dst.Tables[0].Rows[0]["IDCard"].ToString();
                labGovern.Text = UnitClass.GetGovernName(dst.Tables[0].Rows[0]["GovernID"].ToString());
                labUnti.Text = UnitClass.getUnitName(dst.Tables[0].Rows[0]["UnitID"].ToString());
                labApplyName.Text = dst.Tables[0].Rows[0]["Apply_Name"].ToString();
                labSubject.Text = Subject.getSubjectNameBySubjectID(dst.Tables[0].Rows[0]["SubjectID"].ToString());
                labSpeciality.Text = Subject.getSpecialityName(dst.Tables[0].Rows[0]["SpecialityID"].ToString());
            }
        }

        #region <<  保存PPT  >>
        protected void butSavePPT_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["IDCard"] != null && Session["ApplyPeriod"]!=null)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["IDCard"].ToString()) && !String.IsNullOrEmpty((string)Session["ApplyPeriod"]))
                {
                    string strIDCard = Request.QueryString["IDCard"].ToString();
                    string strPeriod = (string)Session["ApplyPeriod"];
                    string strFullFolderPath = common.getAppSetting("FolderforSavePath") + "\\" + strPeriod;
                    string LoadFullPath = common.getAppSetting("FolderforLoadPath") + "/" + strPeriod;
                    common.CreateFolder(strFullFolderPath);
                    HttpFileCollection hfc = Request.Files;
                    for (int i = 0; i < hfc.Count; i++)
                    {
                        if (hfc.Keys[i].ToLower().Trim() == "fileppt")
                        {
                            HttpPostedFile hpf = hfc[i];
                            if (hpf.ContentLength > 0)
                            {
                                string FileFullPath = strFullFolderPath + "\\" + strIDCard.Trim()  + System.IO.Path.GetExtension(hpf.FileName);
                                if (File.Exists(FileFullPath))
                                {
                                    File.Delete(FileFullPath);
                                }
                                hpf.SaveAs(FileFullPath);
                                string LoadPath = LoadFullPath + "/" + strIDCard.Trim() + System.IO.Path.GetExtension(hpf.FileName);
                                string PPTFile = strIDCard.Trim() + System.IO.Path.GetExtension(hpf.FileName);
                                ShowPPT.Visible = true;
                                ShowPPT.NavigateUrl = LoadPath;

                                ApplyClass.ApplyPPTUpdate(Request.QueryString["ApplyID"].ToString(), PPTFile);
                            }
                        }
                    }
                }
            }
        }
        #endregion

        protected void butBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("PPTUpload.aspx");
        }
    }
}
